# The make file for BCSLib

# compiler configuration

ifndef CXX
CXX=g++
endif

ifeq ($(CXX), clang++)
STDFLAGS=-std=c++0x -stdlib=libc++ -U__STRICT_ANSI__
else
STDFLAGS=-std=c++0x
endif

ifndef GTEST_HOME
$(error GTEST_HOME is not defined)
endif

WARNING_FLAGS=-Wall -Wextra -Wconversion 

IMF_LINK=-L$(ICC_ROOT)/lib -limf

MAIN_TEST_PRE=-isystem $(GTEST_HOME)/include -DGTEST_USE_OWN_TR1_TUPLE test/slipp_test_main.cpp
MAIN_TEST_POST=$(GTEST_HOME)/lib/libgtest.a -lpthread

CXXFLAGS_DBG=$(STDFLAGS) $(WARNING_FLAGS) -isystem $(EIGEN_ROOT) -I. 
CXXFLAGS=$(STDFLAGS) $(WARNING_FLAGS) -O3 -msse4.2 $(IMF_LINK) -isystem $(EIGEN_ROOT) -I. 

TBIN=bin
LIB=lib

#-----------------------------

BASE_HEADERS=\
	slipp/base/config.h \
	slipp/base/basic_defs.h \
	slipp/base/lang_utils.h \
	slipp/base/caches.h \
	slipp/base/timer.h \
	slipp/base/math_base.h \
	slipp/eigen_ex/eigen_common.h \
	slipp/eigen_ex/eigen_share.h \
	slipp/eigen_ex/eigen_efuns.h \
	slipp/eigen_ex/eigen_algorithms.h \
	slipp/base/arrays.h
	
PROB_BASE_HEADERS=\
	slipp/prob_base/rstream.h \
	slipp/prob_base/pdistr_base.h \
	slipp/prob_base/uniform_distr.h \
	slipp/prob_base/normal_distr.h \
	slipp/prob_base/discrete_distr.h \
	slipp/prob_base/exponential_distr.h

#-----------------------------

.PHONY: all
all: try test

.PHONY: try
try: $(TBIN)/do_try

.PHONY: test
test: $(TBIN)/test_arrays $(TBIN)/test_rstream $(TBIN)/test_basic_distrs

.PHONY: clean
clean: clean_test clean_lib

.PHONY: clean_test
clean_test:
	-rm $(TBIN)/*

.PHONY: clean_lib
clean_lib:
	-rm $(LIB)/*


#------------------

$(TBIN)/do_try:	$(BASE_HEADERS) $(PROB_BASE_HEADERS) test/do_try.cpp
	$(CXX) $(CXXFLAGS) test/do_try.cpp -o $@ 

#------------------

$(TBIN)/test_arrays: $(BASE_HEADERS) test/test_arrays.cpp
	$(CXX) $(CXXFLAGS) $(MAIN_TEST_PRE) test/test_arrays.cpp $(MAIN_TEST_POST) -o $@

$(TBIN)/test_rstream: $(BASE_HEADERS) slipp/prob_base/rstream.h test/test_rstream.cpp
	$(CXX) $(CXXFLAGS) $(MAIN_TEST_PRE) test/test_rstream.cpp $(MAIN_TEST_POST) -o $@
	
$(TBIN)/test_basic_distrs: $(BASE_HEADERS) $(PROB_BASE_HEADERS) test/test_basic_distrs.cpp
	$(CXX) $(CXXFLAGS) $(MAIN_TEST_PRE) test/test_basic_distrs.cpp $(MAIN_TEST_POST) -o $@

